package com.eqdd.yiqidian.ui.companyspace

import android.view.View
import android.widget.TextView
import com.eqdd.nextinputs.StaticScheme
import com.eqdd.yiqidian.bean.ContactWayBean
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean
import com.eqdd.yiqidian.http.DialogCallBack
import com.eqdd.yiqidian.http.HttpConfig
import com.eqdd.yiqidian.http.HttpResult
import com.eqdd.yiqidian.kotlin.BaseInfoActivity
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_title.*
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.toast

/**
 * Created by jhj on 18-6-23.
 */
class ContactWayInfoActivity : BaseInfoActivity() {

    var contactWayBean: ContactWayBean? = null

    override val topbar: String
        get() = "联系我们"


    override fun initBinding() {
        super.initBinding()
        tv_right.visibility = View.VISIBLE
       /* tv_right.onClick {
            if (checkParams()) {
                toast("请填写完整信息")
                return@onClick
            }

            val bean = slimAdapterEx.data
            if ((it as TextView).text == "新增") {
                OkGo.post<HttpResult<*>>(HttpConfig.BASE_URL + HttpConfig.COMPANY_CONTACT_ADD)
                        .params("userGuid", user.guid)
                        .params("companyId", user.companyId)
                        .params("Contacts", bean[0].content)
                        .params("ContactsNumber", bean[1].content)
                        .params("SeatMachine", bean[2].content)
                        .params("Fax", "")
                        .params("Email", bean[3].content)
                        .params("Address", bean[4].content)
                        .execute(object : DialogCallBack<HttpResult<*>>(this@ContactWayInfoActivity) {
                            override fun onSuccess(response: Response<HttpResult<*>>?) {
                                val result = response?.body()
                                if (result?.status == 200) {
                                    toast("上传成功")
                                }
                            }
                        })
            } else {
                val para = "{${bean[0].content},${bean[1].content},${bean[2].content},${""},${bean[3].content},${bean[4].content}}"
                contactWayBean?.let {
                    OkGo.post<HttpResult<*>>(HttpConfig.BASE_URL + HttpConfig.COMPANY_CONTACT_IPDATE)
                            .params("userGuid", user.guid)
                            .params("companyId", user.companyId)
                            .params("contactId", it.id)
                            .params("para", para)
                            .execute(object : DialogCallBack<HttpResult<*>>(this@ContactWayInfoActivity) {
                                override fun onSuccess(response: Response<HttpResult<*>>?) {
                                    val result = response?.body()
                                    if (result?.status == 200) {
                                        toast("修改成功")
                                    }
                                }
                            })
                }
            }
        }*/
    }


    override fun initData() {
        super.initData()
        OkGo.post<HttpResult<ContactWayBean>>(HttpConfig.BASE_URL + HttpConfig.COMPANY_CONTACT_INFO)
                .params("companyId", user.companyId)
                .execute(object : DialogCallBack<HttpResult<ContactWayBean>>(this) {
                    override fun onSuccess(response: Response<HttpResult<ContactWayBean>>?) {
                        val result = response?.body()
                        if (result?.status == 200) {
                            contactWayBean = result.items
                            setEditBeans()
                            slimAdapterEx.notifyDataSetChanged()
                           /* if (contactWayBean != null) {
                                tv_right.text = "修改"
                                setEditBeans()
                                slimAdapterEx.notifyDataSetChanged()
                            } else {
                                tv_right.text = "新增"
                            }
*/
                        }
                    }
                })
    }

    override fun itemClick(p: Int) {


    }

    override fun setEditBeans() {
        datas?.clear()
        datas.add(SlimEditHintBean("联  系  人", contactWayBean?.contacts, 0))
        datas.add(SlimEditHintBean("联系方式", contactWayBean?.contactNumber, 1))
        datas.add(SlimEditHintBean("座       机", contactWayBean?.seatMachine, 2))
        datas.add(SlimEditHintBean("邮       箱", contactWayBean?.email, 3))
        datas.add(SlimEditHintBean("地       址", contactWayBean?.address, 4))
    }

}